import { DataTypes } from 'sequelize'
const seq = require('../db/seq')
const PermisModels = require('./permis')

const RoleToPermisModels: any = seq.define('role_permis', {
  role_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true,
    references: {
      model: 'role',
      key: 'identity'
    }
  },
  permis_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true,
    references: {
      model: 'permis',
      key: 'id'
    }
  }
}, {
  tableName: 'role_permis',
  timestamps: false,
  indexes: [
    {
      name: "PRIMARY",
      unique: true,
      using: "BTREE",
      fields: [
        { name: "role_id" },
        { name: "permis_id" },
      ]
    },
    {
      name: "permis_idx",
      using: "BTREE",
      fields: [
        { name: "permis_id" },
      ]
    },
  ]
});


RoleToPermisModels.belongsTo(PermisModels, {
  foreignKey: 'permis_id',
  as: 'permis_info'
})

module.exports = RoleToPermisModels